home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 5927 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.7 KB  |  102 lines

  1. Path: vixen.cso.uiuc.edu!arh0268!not-for-mail
  2. From: Dannyman@enteract.com (Unknown)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Bored? Tell me why my code crashes! :)
  5. Date: 22 Mar 1996 03:02:57 GMT
  6. Organization: University of Illinois at Urbana
  7. Message-ID: <4it591$aov@vixen.cso.uiuc.edu>
  8. NNTP-Posting-Host: arh0268.urh.uiuc.edu
  9. X-Newsreader: TIN [AMIGA 1.3 950726BETA PL0]
  10.  
  11.    Short program follows introduction!
  12.  
  13.    It works, sometimes, but just crashes others. As nearly as I can tell,
  14. it's the pettern matching stuff .... everything else seems to work if I
  15. remove these bits. If I pass no wildcards, in fact, the thing works fine,
  16. although the output is rather dull.
  17.  
  18.    Quick background on program function;
  19.  
  20.    Takes in a statsfile generated by another program I'm writing, and
  21. generates "top ten" statistics, matched, preferably to a wildcard pattern.
  22. It's a web-based project, so you can see sample input files at;
  23.  
  24. http://arh0268.urh.uiuc.edu/stats/hosts.raw
  25.                                  /requested.raw
  26.                                  /referers.raw
  27.  
  28.    You can see a script meant to run the freak, among other things, in a
  29. script at;
  30.  
  31. http://arh0268.urh.uiuc.edu/s/dostats (Program name here is t10 ...)
  32.  
  33.    As well, *all* critiques of this code and my approach to it's
  34. implementation, suggestions for better elegance/stability or whatever are
  35. welcome. :) I'm a newbie ...
  36.  
  37.    (Compiled under GCC ...)
  38.  
  39.    Code follows ...
  40.  
  41. --
  42.  
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45. #include <string.h>
  46.  
  47. #include <proto/dos.h>
  48.  
  49. #define BUFLEN 200
  50.  
  51. main(int argc, char *argv[])
  52. {
  53.   BPTR readin;
  54.   
  55.   char buf[BUFLEN];
  56.   char data[BUFLEN-10];
  57.   char chits[10];
  58.   int ctr;
  59.   unsigned long hits, tot;
  60.  
  61.   char match[514];
  62.   char fallback[] = "#?";
  63.   
  64.   if(!argc)  /* If no argc passed, program was started from Workbench ... */
  65.     {
  66.       printf("Sorry, this program must be executed at command-line!\n");
  67.       exit(0);
  68.     }
  69.  
  70.   if((readin = Open(argv[1], MODE_OLDFILE)) != 0)
  71.     {
  72.       if(ParsePatternNoCase(argv[2], match, 514) == -1)
  73.    {
  74.      printf("AAAGH!\n");
  75.      Close(readin);
  76.      exit(0);
  77.    }
  78.  
  79.       FGets(readin, buf, BUFLEN);
  80.       
  81.       strcpy(chits, strtok(buf, " "));
  82.       tot = atoi(chits);
  83.       
  84.       printf("%6d Total\n\n", tot);
  85.       
  86.       for(ctr = 0; (ctr < 10 && (FGets(readin, buf, BUFLEN) != NULL)); )
  87.    {
  88.      strcpy(chits, strtok(buf, " "));
  89.      hits = atoi(chits);
  90.      strcpy(data, strtok(NULL, "\n"));
  91.      if (MatchPatternNoCase(match, data))
  92.        {
  93.          printf("%6d %s (%.5g%%)\n", hits, data, (float)hits/tot*100);
  94.          ctr++;
  95.        }
  96.    }
  97.       Close(readin);
  98.     }
  99.   else
  100.     printf("Could not open %s !\nUsage: %s <input-file> [include-pattern]\n", argv[1], argv[0]);
  101. }
  102.